package com.hilihili.transcode;

import com.hilihili.config.TranscodeConfig;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * cpu cuda 混合模式转码
 * @author machi
 * @date 2024/01/31
 */
public class MixtureCUDACommand extends AbstractTranscodeCommand {
    private TranscodeConfig transcodeConfig;

    public MixtureCUDACommand(TranscodeConfig transcodeConfig) {
        this.transcodeConfig = transcodeConfig;
    }

    @Override
    List<String> getTranscodeCommand(String ffmpeg) {

        //ffmpeg -i input.mp4
        // -filter_complex
        // "[0:v]split=4[s0][s1][s2][s3];[s0]scale=1920x1080:force_original_aspect_ratio=decrease[0v];[s1]scale=1280x720:force_original_aspect_ratio=decrease[1v];[s2]scale=858x480:force_original_aspect_ratio=decrease[2v];[s3]scale=630x360:force_original_aspect_ratio=decrease[3v]" -map "[0v]"
        // -map 0:1 -map "[1v]" -map 0:1 -map "[2v]" -map 0:1 -map "[3v]" -map 0:1 -b:v:0 1800k -b:v:1 1200k -b:v:2 750k -b:v:3 550k -c:v h264_nvenc -c:a copy -var_stream_map "v:0,a:0,name:1080p v:1,a:1,name:720p v:2,a:2,name:480p v:3,a:3,name:360p"
        // -master_pl_name index.m3u8 -f hls -hls_time 10 -hls_playlist_type vod -hls_list_size 0 -hls_segment_filename "%v/%06d.ts" %v/index.m3u8

        return new ArrayList<>(Arrays.asList(
                ffmpeg,
                "-i",getSource() ,
                "-filter_complex", "\"[0:v]split=4[s0][s1][s2][s3];[s0]scale=1920x1080:force_original_aspect_ratio=decrease[0v];[s1]scale=1280x720:force_original_aspect_ratio=decrease[1v];[s2]scale=858x480:force_original_aspect_ratio=decrease[2v];[s3]scale=630x360:force_original_aspect_ratio=decrease[3v]\"",
                "-map", "[0v]", "-map", "0:1",
                "-map", "[1v]", "-map", "0:1",
                "-map", "[2v]", "-map", "0:1",
                "-map", "[3v]", "-map", "0:1",
                "-b:v:0", "1800k", "-b:v:1", "1200k", "-b:v:2", "750k", "-b:v:3", "550k",
                "-c:v", "h264_nvenc",
                "-c:a", "copy",
                "-var_stream_map", "v:0,a:0,name:1080p v:1,a:1,name:720p v:2,a:2,name:480p v:3,a:3,name:360p",
                "-master_pl_name", "index.m3u8",
                "-hls_key_info_file",getKeyInfo(),
                "-f", "hls",
                "-hls_time", transcodeConfig.getTsSeconds(),
                "-hls_playlist_type", "vod",
                "-hls_list_size", "0",
                "-hls_segment_filename", "%v/%06d.ts",
                "%v/index.m3u8"
        ));

    }



}
